//
//  StatusToolBar.swift
//  微博Swift
//
//  Created by  justinchou on 16/2/29.
//  Copyright © 2016年  justinchou. All rights reserved.
//

import UIKit

class StatusToolBar: UIView {
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // MARK: - 私有控件
    /// 转发按钮
    private let retweetedButton: UIButton = UIButton(
        title: "转发",
        fontSize: 12,
        imageName: "timeline_icon_retweet",
        backgroundImageName: "timeline_card_bottom_background")
    /// 评论按钮
    private let commentButton: UIButton = UIButton(
        title: "评论",
        fontSize: 12,
        imageName: "timeline_icon_comment",
        backgroundImageName: "timeline_card_bottom_background")
    private let likeButton: UIButton = UIButton(
        title: "赞",
        fontSize: 12,
        imageName: "timeline_icon_unlike",
        backgroundImageName: "timeline_card_bottom_background")
    

}

// MARK: - 设置界面布局
extension StatusToolBar {
    
    private func setupUI() {
        
        backgroundColor = superview?.backgroundColor
        
        addSubview(retweetedButton)
        addSubview(commentButton)
        addSubview(likeButton)
        
        //设置button中图片和文本之间的间距
        let inset = UIEdgeInsets(top: 0, left: 12, bottom: 0, right: 0)
        retweetedButton.titleEdgeInsets = inset
        commentButton.titleEdgeInsets = inset
        likeButton.titleEdgeInsets = inset
        
        retweetedButton.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self)
            make.left.equalTo(self)
            make.bottom.equalTo(self)
        }
        
        commentButton.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self)
            make.bottom.equalTo(self)
            make.left.equalTo(retweetedButton.snp_right)
            make.width.equalTo(retweetedButton)
        }
        
        likeButton.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self)
            make.bottom.equalTo(self)
            make.left.equalTo(commentButton.snp_right)
            make.right.equalTo(self)
            make.width.equalTo(commentButton)
        }
        
        // MARK: - 添加分隔线
        let iv1 = UIImageView(image: UIImage(named: "timeline_card_bottom_line"))
        let iv2 = UIImageView(image: UIImage(named: "timeline_card_bottom_line"))
        
        addSubview(iv1)
        addSubview(iv2)
        
        iv1.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(retweetedButton.snp_right)
            make.centerY.equalTo(commentButton)
        }
        iv2.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(commentButton.snp_right)
            make.centerY.equalTo(commentButton)
        }
        
        
    }
}
